home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / foss11b3.zip / DEVELOP / UTILCOLL / TOPTEN.PAS < prev    next >
Pascal/Delphi Source File  |  1995-10-24  |  14KB  |  421 lines

  1. program TopTen;
  2. uses
  3.   TParam,
  4.   TFileIO,
  5.   TOSInt,
  6.   ApiInt,
  7.   Bits,
  8.   Types;
  9.  
  10. label
  11.   NextTopUser,
  12.   NextDown,
  13.   NextUp,
  14.   NextFDown,
  15.   NextFUp;
  16.  
  17. type
  18.   PTopTenBull      = ^TTopTenBull;
  19.   TTopTenBull      = object
  20.     Language       : Char;
  21.     SkipFile       : string;
  22.     AreaCode       : string;
  23.     BullPath       : string;
  24.  
  25.     constructor Init;
  26.     destructor Done;
  27.  
  28.     procedure ReadParams;
  29.     procedure CreateBull;
  30.   end;
  31.  
  32. var
  33.   TopTenBull       : PTopTenBull;
  34.  
  35. constructor TTopTenBull.Init;
  36. begin
  37.   dllInit( '', 0 );
  38. end; { contructor Init }
  39.  
  40. destructor TTopTenBull.Done;
  41. begin
  42. end; { destructor Done }
  43.  
  44. procedure TTopTenBull.ReadParams;
  45. begin
  46.   if Par^.SwAct['L'] then
  47.     case UpCh( Par^.SwStr['L', 1] ) of
  48.       'A': Language := 'A';
  49.       'E': Language := 'E';
  50.       'N': Language := 'N';
  51.     else
  52.       Language := 'A';
  53.     end
  54.   else Language := 'A';
  55.  
  56.   SkipFile := '';
  57.   if Par^.SwAct['S'] then
  58.     if FileExist( Par^.SwStr['S'] ) then
  59.       SkipFile := Par^.SwStr['S'];
  60.  
  61.   if Par^.SwAct['A'] then AreaCode := Par^.SwStr['A']
  62.   else AreaCode := 'MAIN';
  63.  
  64.   BullPath := Par^.Str[1];
  65. end; { procedure ReadParams }
  66.  
  67. procedure TTopTenBull.CreateBull;
  68. type
  69.   PTopTenData      = ^TTopTenData;
  70.   TTopTenData      = record
  71.     TotalTime,
  72.     TotalOn,
  73.     TotalDown,
  74.     TotalUp,
  75.     TotalFiles     : LongInt;
  76.     TotalMDown,
  77.     TotalMUp,
  78.     TotalMB        : Real;
  79.  
  80.     TopUserTime,
  81.     TopUserCnt,
  82.     Down,
  83.     Up             : array[1..10] of LocUsers;
  84.  
  85.     FDown,
  86.     FUp            : array[1..10] of TFileRec;
  87.   end;
  88.  
  89. const
  90.   TopLine          = '┌────────────────────────────────────┐  ┌────────────────────────────────────┐';
  91.   BottomLine       = '└────────────────────────────────────┘  └────────────────────────────────────┘'#13#10 +
  92.                      '                                                                              '#13#10'%!m%';
  93.  
  94. var
  95.   T10               : PTopTenData;
  96.   User              : LocUsers;
  97.   FPos              : LongInt;
  98.   L1, L2            : LongInt;
  99.   Area              : Area_Config_Record;
  100.   Dir               : TFileRec;
  101.   OutE,
  102.   OutN              : TFile;
  103.   Year              : Word;
  104.   Month, Day        : Byte;
  105.   TmpStr            : string;
  106.   TmpTime           : LongInt;
  107.  
  108. {}function  SkipUser( Name : string ) : Boolean;
  109.   var
  110.     SkFile         : TFile;
  111.     NameMask       : string;
  112.  
  113.   begin
  114.     if not ( Length( SkipFile ) = 0 ) then
  115.       with SkFile do
  116.       begin
  117.         Assign( SkipFile,
  118.                 fmReadOnly or fmDenyWrite,
  119.                 1,
  120.                 faNormalAccess,
  121.                 ftMaxTimeout );
  122.         Reset;
  123.  
  124.         while not Eof do
  125.         begin
  126.           ReadTextln( NameMask );
  127.           if LookInIf( Name, NameMask ) then
  128.           begin
  129.             Close;
  130.             SkipUser := TRUE;
  131.             exit;
  132.           end;
  133.         end;
  134.  
  135.         Close;
  136.       end;
  137.  
  138.     SkipUser := FALSE;
  139. {}end;
  140.  
  141. {}procedure PrintOut           ( Lang : Char; Txt : String );
  142.   begin
  143.     if ( Lang in ['A', 'E'] ) then OutE.WriteTextln( Txt );
  144.     if ( Lang in ['A', 'N'] ) then OutN.WriteTextln( Txt );
  145. {}end; { Procedure PrintOut }
  146.  
  147. begin
  148.   New( T10 );
  149.   FillChar( T10^, SizeOf( T10^ ), 0 );
  150.  
  151.   Write( '  - Scanning user: ' );
  152.   FPos := 0;
  153.   while fioReadLocalUsr( User, FPos ) do
  154.   begin
  155.     OS^.Sleep( 2 );
  156.     Inc( FPos );
  157.     if ( Killed in User.Flags ) then Continue;
  158.  
  159.     Write( Fill( User.UserName, High( User.UserName ), ' ' ) +
  160.            Fill( '', High( User.UserName ), #8 ));
  161.  
  162.     with T10^ do
  163.     begin
  164.       Inc( TotalTime, User.TimeTotal );
  165.       Inc( TotalOn, User.TimesOn );
  166.       Inc( TotalDown, User.Downloads );
  167.       TotalMDown := TotalMDown + User.DownloadKB / 1024;
  168.       Inc( TotalUp, User.Uploads );
  169.       TotalMUp := TotalMUp + User.UploadKB / 1024;
  170.  
  171.       if not SkipUser( User.UserName ) then
  172.       begin
  173.         for L1 := 1 to 10 do
  174.           if ( TopUserTime[L1].TimeTotal < User.TimeTotal ) then
  175.           begin
  176.             for L2 := 9 downto L1 do
  177.               TopUserTime[L2 + 1] := TopUserTime[L2];
  178.             TopUserTime[L1] := User;
  179.             Break;
  180.           end;
  181.  
  182.         for L1 := 1 to 10 do
  183.           if ( TopUserCnt[L1].TimesOn < User.TimesOn ) then
  184.           begin
  185.             for L2 := 9 downto L1 do
  186.               TopUserCnt[L2 + 1] := TopUserCnt[L2];
  187.             TopUserCnt[L1] := User;
  188.             Break;
  189.           end;
  190.  
  191.         for L1 := 1 to 10 do
  192.           if ( Down[L1].Downloads < User.Downloads ) then
  193.           begin
  194.             for L2 := 9 downto L1 do
  195.               Down[L2 + 1] := Down[L2];
  196.             Down[L1] := User;
  197.             Break;
  198.           end;
  199.  
  200.         for L1 := 1 to 10 do
  201.           if ( Up[L1].Uploads < User.Uploads) then
  202.           begin
  203.             for L2 := 9 downto L1 do
  204.               Up[L2 + 1] := Up[L2];
  205.             Up[L1] := User;
  206.             Break;
  207.           end;
  208.       end  { if SkipUser( User ) }
  209.       else
  210.       begin
  211.         Writeln( Fill( '', 19, #8 ) +
  212.                  '  - Skipped user: ' + User.UserName + '. ' );
  213.         Write( '  - Scanning user: ' );
  214.       end; { if SkipUser( User ) else }
  215.     end;
  216.   end;
  217.   Write( Fill( '', High( User.UserName ), ' ') +
  218.          Fill( '', 19 + High( User.UserName ), #8 ));
  219.  
  220.   fioFindAreaCode( Area, AreaCode,  0 );
  221.   Write( '  - Scanning file: ' );
  222.   FPos := 0;
  223.   while fioReadFileRec( Dir, Area, FPos ) do
  224.   begin
  225.     OS^.Sleep( 2 );
  226.     Inc( FPos );
  227.     if ( KilledFile in Dir.FileFlags ) then Continue;
  228.  
  229.     Write( Fill( Dir.FileName, High( Dir.FileName ), ' ' ) +
  230.            Fill( '', High( Dir.FileName ), #8 ));
  231.  
  232.     with T10^ do
  233.     begin
  234.       Inc( TotalFiles );
  235.       TotalMB := TotalMB + Dir.Size / 1048576;
  236.  
  237.       for L1 := 1 to 10 do
  238.         if (FDown[L1].Downloads<Dir.Downloads) then
  239.         begin
  240.           for L2 := 9 downto L1 do
  241.             FDown[L2+1] := FDown[L2];
  242.           FDown[L1] := Dir;
  243.           Break;
  244.         end;
  245.     end;
  246.   end;
  247.   Write( Fill( '', High( User.UserName ), ' ') +
  248.          Fill( '', 19 + High( User.UserName ), #8 ));
  249.  
  250.   if ( Language in ['A', 'E'] ) then
  251.   begin
  252.     with OutE do
  253.     begin
  254.       Assign( BullPath + '.E',
  255.               fmWriteOnly or fmExclusive,
  256.               1,
  257.               faNormalAccess,
  258.               ftMaxTimeout );
  259.       ReWrite;
  260.     end;
  261.   end;
  262.  
  263.   if ( Language in ['A', 'N'] ) then
  264.   begin
  265.     with OutN do
  266.     begin
  267.       Assign( BullPath + '.N',
  268.               fmWriteOnly or fmExclusive,
  269.               1,
  270.               faNormalAccess,
  271.               ftMaxTimeout );
  272.       ReWrite;
  273.     end;
  274.   end;
  275.  
  276.   with T10^ do
  277.   begin
  278.     Date( Year, Month, Day );
  279.     TmpTime := TimeNow;
  280.     PrintOut( 'E', '' + Fill( ' TopTen statistics', 39, ' ' ) +
  281.                    PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
  282.     PrintOut( 'N', '' + Fill( ' Ti på topp statistikk', 39, ' ' ) +
  283.                    PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
  284.     PrintOut( 'A', '' );
  285.     PrintOut( 'E', '' + Center( 'TOP-10 USERS', 78, ' ' ));
  286.     PrintOut( 'N', '' + Center( 'TI PÅ TOPP BRUKERE', 78, ' ' ));
  287.     PrintOut( 'A', '' );
  288.     PrintOut( 'E', Center( 'Total user time: ' + I2S( TotalTime, 0 ), 78, ' ' ));
  289.     PrintOut( 'N', Center( 'Total bruker tid: ' + I2S( TotalTime, 0 ) ,78, ' ' ));
  290.     PrintOut( 'E', Center( 'Total number of logons: ' + I2S( TotalOn, 0 ), 78, ' ' ));
  291.     PrintOut( 'N', Center( 'Antall pålogginger: ' + I2S( TotalOn, 0 ), 78, ' ' ));
  292.     PrintOut( 'A', '' );
  293.     PrintOut( 'E', ' Username                     Minutes    Username                      Logons ' );
  294.     PrintOut( 'N', ' Brukernavn                  Minutter    Pålogginger              Pålogginger ' );
  295.     PrintOut( 'A', TopLine );
  296.  
  297.     for L1 := 1 to 10 do
  298.     begin
  299.       if ( L1 = 1 ) then TmpStr := ''
  300.       else TmpStr := '';
  301.       PrintOut( 'A',